/**
 * Copyright (C) 2018-2022
 * All rights reserved, Designed By www.yixiang.co
 * 注意：
 * 本软件为www.yixiang.co开发研制
 */
package co.yixiang.controller.buyer.help;

import cn.hutool.core.util.ObjectUtil;
import co.yixiang.common.exception.BadRequestException;
import co.yixiang.common.utils.ResultUtil;
import co.yixiang.common.vo.ResultMessage;
import co.yixiang.modules.mp.entity.domain.YxHelp;
import co.yixiang.modules.mp.entity.domain.YxHelpCategory;
import co.yixiang.modules.mp.entity.dto.YxHelpQueryCriteria;
import co.yixiang.modules.mp.entity.vo.YxHelpCategoryVoF;
import co.yixiang.modules.mp.entity.vo.YxHelpVo;
import co.yixiang.modules.mp.service.YxHelpCategoryService;
import co.yixiang.modules.mp.service.YxHelpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author hupeng
 * @date 2019-10-07
 */
@Api(tags = "商城:帮助管理")
@RestController
@RequestMapping("/help")
public class HelpBuyerController {
    @Autowired
    private YxHelpService helpService;
    @Autowired
    private YxHelpCategoryService categoryService;

    @ApiOperation(value = "查询帮助分类")
    @GetMapping(value = "/category")
    public ResultMessage<List<YxHelpCategoryVoF>> getCategory() {
         List<YxHelpCategoryVoF> yxHelpCategoryVoFS = categoryService.queryAllByVo();
         return ResultUtil.data(yxHelpCategoryVoFS);
    }

    @ApiOperation(value = "分页查询帮助信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cid", value = "分类ID", paramType = "query"),
    })
    @GetMapping
    public ResultMessage<Map<String, Object>> getYxHelps(YxHelpQueryCriteria criteria, Pageable pageable) {
        final Map<String, Object> stringObjectMap = helpService.queryAllToVo(criteria, pageable);
        return ResultUtil.data(stringObjectMap);
    }

    @ApiOperation(value = "阅览帮助详情")
    @GetMapping(value = "/read/{id}")
    public ResultMessage<YxHelpVo> readYxHelps(@PathVariable Integer id) {
        if(ObjectUtil.isEmpty(id)) {
            throw new BadRequestException("查询参数错误:帮助ID不能为空");
        }
        final YxHelpVo yxHelpVo = helpService.readHelpVo(id);
        return ResultUtil.data(yxHelpVo);
    }
}
